package com.cz.pg;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

public class DeviceDataInsert {
    public static void main(String[] args) {
        String dbGroup = "pg";
        Date date = new Date();
        for(int i=0;i< 10000;i++){
            List<Entity> entityList = new ArrayList<>();
            for (int j = 0; j < 10000; j++) {
                Entity entity = new Entity("device_data");
                entity.set("time", "Device" + j);
                entity.set("is_online", RandomUtil.randomInt(0,2));
                entity.set("device_id", j);
                entity.set("device_port", 8193);
                entity.set("nc_type", "FanucSeriesOi-MD");
                entity.set("part_count_total", RandomUtil.randomInt(0, 1000));
                entity.set("main_program_name", "NCProgram" + j);
                entity.set("current_tool", j);
                entity.set("spindle_override", RandomUtil.randomInt());
                entity.set("feedrate_override", RandomUtil.randomInt());
                entity.set("spindle_speed_actual", RandomUtil.randomInt());
                entity.set("spindle_feed_speed_actual", RandomUtil.randomInt());
                entity.set("run_time_total", RandomUtil.randomInt());
                entity.set("cut_time_total", RandomUtil.randomInt());
                entity.set("cycle_time", RandomUtil.randomInt());
                entity.set("get_power_on_time_total", RandomUtil.randomInt());
                entity.set("alarm_code", RandomUtil.randomInt());
                entity.set("alarm_msg", RandomUtil.randomInt());
                entity.set("is_run", RandomUtil.randomInt(0,2));
                entity.set("nc_mode", RandomUtil.randomString(5));
                entity.set("spindle_load_rate", RandomUtil.randomInt());
                entity.set("id", IdUtil.getSnowflake().nextId());

                Timestamp timestamp = new Timestamp(DateUtil.offsetMillisecond(date, i*10 + j).getTime());

                entity.set("time", timestamp);
                entityList.add(entity);
            }
            try {
                Db.use(dbGroup).insert(entityList);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }

}
